/**
 * import { useMessage } from '@/composables/useMessage';
 *
 * const $message = useMessage();
 *
 * $message.info('这是一条信息消息');
 * $message.success('操作成功完成！');
 * $message.warning('这是一条警告消息');
 * $message.error('这是一条错误消息');
 *
 * $message.close('message-id');
 */

import { inject } from 'vue';

import type { MessageAPI } from '@/components/Message';

export const useMessage = (): MessageAPI => {
  const message = inject<MessageAPI>('$message');

  if (!message) {
    throw new Error('useMessage must be used within a component that has MessagePlugin installed');
  }

  return message;
};
